$(document).ready(default_init);

function default_init()
{
    $('.toggle').click(function(){$('#order_detailed').toggleClass('none');});
    $('#toolbar_refresh,#toolbar_refresh_order, #toolbar_refresh_product').click(function(){ location.reload();})
    $('#toolbar_save').click(insertClient);
    $('#toolbar_save_order').click(insertOrder);
    $('#toolbar_save_product').click(insertFabricator);
    $('#toolbar_report_cl').click(function(){window.location='/someclient/newbookexcel/'+$('#id').val();});
    $('#toolbar_report_order').click(function(){window.location='/someorder/newbookexcel/'+$('#id').val();});
    $('#toolbar_print').click(function(){window.location='/someclient/index/'+$('#id').val()+'/print';});
    $('#toolbar_print_order').click(function(){window.location='/someorder/index/'+$('#id').val()+'/print';});
}

/*======================Изменение данных клиента==============================*/
function insertClient()
{
    if($('form').validationEngine('validate'))
    {
        $.ajax({
            url: '/someclient/insertdata/',
            type: "POST",
            data:
            {
                'id':$('#id').val(),
                'name':$('#name').val(),
                'first_name':$('#first_name').val(),
                'second_name':$('#second_name').val(),
                'phone':$('#phone').val(),
                'email':$('#email').val(),
                'region':$('#region option:selected').text(),
                'city':$('#city option:selected').text(),
                'street':$('#street').val(),
                'house':$('#house').val(),
                'porch':$('#porch').val(),
                'houseroom':$('#houseroom').val(),
            },                     
            success: function (data) {
                location.reload(); 
            }               
        });
    }
}

/*==============================Изменение Заказа==============================*/
function insertOrder()
{
    if($('form').validationEngine('validate'))
    {
        $.ajax({
        url: '/someorder/insertdata/',
        type: "POST",
        data:
        {
            'id':$('#id').val(),
            'id_product':$('#product').val(),
            'id_site':$('#site').val(),
            'count': $('#count').val(),
            'discont':$('#discont').val()
        },                     
        success: function (data) {
            location.reload(); 
        }               
        });
    }
}

/*============================Изменение продукта==============================*/
function insertFabricator()
{
    if($('form').validationEngine('validate'))
    {
        $.ajax({
            url: '/someproduct/insertdata/',
            type: "POST",
            data:
            {
               id: $('#id').val(),
               id_category: $('#product_category').val(),
               id_fabricator:$('#id_fabricator_product').val(),
               fabricator: $('#fabricator_product').val(),
               name: $('#s_product_name').val(),
               price:$('#price').val(),
               price_selling:$('#price_selling').val(),
               count:$('#count').val(),
               reserved:$('#reserved').val(),
               path_img:$('#path').val()
            },                     
            success: function(data) 
            {
               location.reload();
            }
        });
    }
}